package util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;


public class FileUtil {
	public static ArrayList<String> loadinFile(String fileLocation) {
		ArrayList<String> content = new ArrayList<String>();
		try {
			FileReader fr = new FileReader(fileLocation);
			BufferedReader br = new BufferedReader(fr);
			String line;
			while (br.ready()) {
				line = br.readLine();
				content.add(line);
			}
			br.close();
			fr.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return content;
	}
	
	public static void outputFile(String fileName, ArrayList<String> contents) {
		try {
			FileWriter fstream = new FileWriter(fileName);
			BufferedWriter out = new BufferedWriter(fstream);
			for (String content : contents) {
				out.write(content.replaceAll("[\\n]", "") + "\n");
			}
			out.close();
		} catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

}
